/******************************************************************************* 
 * Copyright (C) 2012-2015 Microfountain Technology, Inc. All Rights Reserved. 
 * 
 * Unauthorized copying of this file, via any medium is strictly prohibited.   
 * Proprietary and confidential
 * 
 * Last Modified: 2016-4-12 13:56:00
 ******************************************************************************/
package cn.cmcc.online.smsapi.util;

import java.util.HashMap;
import java.util.Map;


import org.json.JSONObject;

import android.content.ContentValues;
import android.os.Process;
import cn.cmcc.online.smsapi.sdk.Iservice.XyCallBack;
import cn.cmcc.online.smsapi.sdk.constant.Constant;
import cn.cmcc.online.smsapi.sdk.db.base.BaseManager;
import cn.cmcc.online.smsapi.sdk.db.entity.MatchCacheManager;
import cn.cmcc.online.smsapi.sdk.dex.DexUtil;
import cn.cmcc.online.smsapi.sdk.log.LogManager;
import cn.cmcc.online.smsapi.sdk.service.baseparse.BaseParseService;
import cn.cmcc.online.smsapi.sdk.threadpool.SmartSmsThreadPoolManager;
import cn.cmcc.online.smsapi.sdk.util.JsonUtil;
import cn.cmcc.online.smsapi.sdk.util.SdkCache;
import cn.cmcc.online.smsapi.sdk.util.StringUtils;
import cn.cmcc.online.smsapi.sdk.util.XyUtil;
/*SDK-616 hewengao 20160912 end*/
/*SDK-635 songzhirong 20161011 start*/
import org.json.JSONArray;
import org.json.JSONException;
/*SDK-635 songzhirong 20161011 end*/
/**
 * 丰富气泡、简单气泡、特征值识别解析接口，解析短信时传入需要解析类型的flag
*/
public class ParseSmsMessage {
    //parse flag
    public final static int DUOQU_SMARTSMS_SHOW_BUBBLE_SIMPLE_FLAG = 1;
    public final static int DUOQU_SMARTSMS_SHOW_BUBBLE_RICH_FLAG = 2;
    public final static int DUOQU_SMARTSMS_SHOW_RECOGNISE_VALUE_FLAG = 8;
    public final static int DUOQU_SMARTSMS_SHOW_URL_VALUE_FLAG = 16;
    /* RM-1374 mobaohua 20170406 start */
    public final static int DUOQU_SMARTSMS_SHOW_URL_PREVIEW_VALUE_FLAG = 24;
    /* RM-1374 mobaohua 20170406 end */
    /* RM-1467 mobaohua 20170406 start */
    public final static int DUOQU_SMARTSMS_SHOW_URL_MSG_MOVIE_FLAG = 32;
    /* RM-1467 mobaohua 20170406 end */
    /* SDK-765 mobaohua 20170419 start */
    public final static int DUOQU_SMARTSMS_SHOW_URL_EXPRESS_INFO_FLAG = 36;
    /* SDK-765 mobaohua 20170419 end */
    
    //has data
    public final static int DUOQU_CALLBACK_UITHREAD_HASDATA = 0;
    public final static int DUOQU_CALLBACK_BACKTHREAD_HASDATA = 1;
    
    /*SDK-514 zhaojiangwei 20160630 start*/
    public final static int DUOQU_CALLBACK_REFRESH_LIST = 2;
    /*SDK-514 zhaojiangwei 20160630 end*/
    
    //parsing status
    public final static int DUOQU_CALLBACK_UITHREAD_NEEDPARSE = -2;
    //local error status
    public final static int DUOQU_CALLBACK_UITHREAD_NODATA = -1;
    public final static int DUOQU_CALLBACK_UITHREAD_SCOLLING = -4;
    public final static int DUOQU_CALLBACK_BACKTHREAD_FAIL = -3;
    //global error status
    public final static int DUOQU_CALLBACK_UITHREAD_PHONENUM_NULL = -1;
    public final static int DUOQU_CALLBACK_UITHREAD_UNKOWN = -5;

    public static void parseMessage(final String msgId, final String phoneNum, final String smsCenterNum,
            final String smsContent, final long smsReceiveTime, int parseFlag, HashMap<String, Object> extend,
            final SdkCallBack xyCallBack, boolean scrollFing) {
        try {
            if(parseFlag == DUOQU_SMARTSMS_SHOW_BUBBLE_RICH_FLAG) {
                //rich bubble
                ParseRichBubbleManager.queryDataByMsgItem(msgId, phoneNum, smsContent,
                        smsReceiveTime, smsCenterNum, 2, xyCallBack, scrollFing, extend);
            } else if(parseFlag == DUOQU_SMARTSMS_SHOW_BUBBLE_SIMPLE_FLAG) {
                //simple bubble
                /*SDK-799 zhaojiangwei 20170612 start */
                Map<String, String>extMap = XyUtil.changeObjMapToStrMap(extend);
                if (extMap==null) {
                    extMap = new HashMap<String, String>();
                    extMap.put("isUseNewAction", "true");
                }
                /*SDK-799 zhaojiangwei 20170612 end */
                ParseBubbleManager.queryDataByMsgItem(msgId, phoneNum, smsContent,
                        smsCenterNum, 1, smsReceiveTime, xyCallBack, scrollFing, extMap);
            } 
        } catch (Throwable e) {
            LogManager.e("XIAOYUAN", "parseMessage error type:" , e);
            /* SDK-584 zhaojiangwei 20160906 start */
            DexUtil.saveExceptionLog(e);
            /* SDK-584 zhaojiangwei 20160906 end */
        }
    }

}
